<?php
/**
 * Created by : Sandi Rizky Kharisma (sandi.informatics08@gmail.com)
 * This Class Generated for CRUD purpose only
 */
class pinjaman extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->library('auth');
        $this->load->library('base');        
    }

    public function get_new_request()
    {
        $this->auth->is_logged_in('form/login');
        
        $this->load->model('crud/m_pinjaman', '', TRUE);
        $this->load->model('palapa_client/m_pinjaman_palapa', '', TRUE);

        $result_client = $this->m_pinjaman_palapa->get("pinjaman.ID_PINJAMAN_PUSAT = 0 AND pinjaman.STATUS = 0");

        if($result_client->num_rows() > 0)
        {
            foreach($result_client->result() as $row)
            {
                $result = $this->m_pinjaman->insert_data($row->ID_ANGGOTA, $row->ID_JENIS_KREDIT, $row->ID_INFO_USAHA,
                            $row->TGL_PINJAMAN, $row->LAMA_PINJAMAN, $row->JUMLAH_PINJAMAN, $row->CICILAN_POKOK, $row->BUNGA);

                $newID = $this->db->insert_id();

                $this->m_pinjaman_palapa->set_id_pinjaman_pusat($row->ID_PINJAMAN, $newID);
            }
        }

        redirect("br-03/peminjaman/list_new");
    }
    
    public function delete($id)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_pinjaman->delete($id);
        echo json_encode($this->response);
    }
}
?>